<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(comld) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
//$handle = fopen("http://192.168.0.185/log/test/$dateTime.'a'", "r");
$handle = fopen("http://192.168.0.184/log/comld/loga.txt", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);

    $id101 = $arr2["arrScene"];
   // $arr3 = json_decode($id101, true);


    $id = $id101["Credit"];
    $id2 = $id101["Ready"];
    $id3 = $id101["Menu"];
    $id4 = $id101["Map"];
    $id5 = $id101["Help"];
    $id6 = $id101["Option"];
    $id7 = $id101["IAP"];
    $id8 = $id101["Shop"];
    $id9 = $id101["Scene0"];
    $id10 = $id101["Scene1"];

    $id11 = $arr2["nGoldGainTotal"];  //2
    $id12 = $arr2["ltWeapon"];
    $id13 = $id12["1"];//InnoKiller
    $id14 = $id12["2"];//LandMine
    $id15 = $id12["3"]; //AirStrike

    $id16 = $id12["4"];//Tower
    $id17 = $id12["5"];//TowerBullet
    $id18 = $arr2["sFirstGame"];

    $id19 = $arr2["fGameTimeTotal"]; //4
    $id20 = $arr2["nTCGainTotal"];
    $id21 = $arr2["nTCNow"];
    $id22 = $arr2["arrItem"];
  
    $id22a = $id22["InnoKiller"];
    $id22b = $id22["LandMine"];
    $id22c = $id22["AirStrike"];
    $id22d = $id22["Tower"];
    $id22e = $id22["TowerBullet"];

    $id27 = $arr2["nGoldNow"];

    $id99 = $arr2["macaddress"];
    $id100 = $arr2["gamename"];
    $id101 = $arr["createdate"];
    $id102 = $arr2["Jailbreak"];
      
    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
    	
        $Credit = $id;
        $Ready = $id2;
        $Menu = $id3;
        $Map = $id4;
        $Help = $id5;
        $options = $id6;
        $IAP = $id7;
        $Shop = $id8;
        $Scene0 = $id9;
        $Scene1 = $id10;
        $nGoldGainTotal = $id11;
        $InnoKiller_ltWeapon = $id13;
        $LandMine_ltWeapon = $id14;
        $AirStrike_ltWeapon = $id15;
        $Tower_ltWeapon = $id16;
        $TowerBullet_ltWeapon = $id17;
        $FirstLoginTime = $id18;
        $fGameTimeTotal = $id19;
        $nTCGainTotal = $id20;
        $nTCNow = $id21;
        $arrItem = $id22;
     
       $InnoKiller_arrItem = $id22a;
       $LandMine_arrItem = $id22b ;
       $AirStrike_arrItem =$id22c;
       $Tower_arrItem = $id22d;
       $TowerBullet_arrItem = $id22e;

       $nGoldNow = $id27;
     
       $deviceid = $id99;
       $gamename = $id100;
       $createdate = $id101;
       $date = $id101;
       $Jailbreak = $id102;
       //var_dump($InnoKiller_arrItemBuyToday);die;

   

      mysql_query("INSERT INTO comld_query_total (Credit,Ready,Menu,Map,Help,options,IAP,
                                               Shop,Scene0,Scene1,nGoldGainTotal,InnoKiller_ltWeapon,LandMine_ltWeapon,AirStrike_ltWeapon,
                                               Tower_ltWeapon,TowerBullet_ltWeapon,FirstLoginTime,fGameTimeTotal,nTCGainTotal,nTCNow,InnoKiller_arrItem,
                                                LandMine_arrItem,AirStrike_arrItem,Tower_arrItem,TowerBullet_arrItem,nGoldNow,deviceid,
                                                gamename,createdate,date,Jailbreak) 
                    VALUES('$Credit','$Ready','$Menu','$Map','$Help','$options','$IAP',
                          '$Shop','$Scene0','$Scene1','$nGoldGainTotal','$InnoKiller_ltWeapon','$LandMine_ltWeapon',
                          '$AirStrike_ltWeapon','$Tower_ltWeapon','$TowerBullet_ltWeapon','$FirstLoginTime','$fGameTimeTotal','$nTCGainTotal','$nTCNow','$InnoKiller_arrItem',
                          '$LandMine_arrItem','$AirStrike_arrItem','$Tower_arrItem','$TowerBullet_arrItem',
                          '$nGoldNow','$deviceid','$gamename','$createdate','$date','$Jailbreak'
)") or die(mysql_error());
    }
}
fclose($handle);
//fclose($fp);
print "Import successful!<br>";

?>
